package net.queue;

import java.util.ArrayList;
import java.util.Queue;

public class ArrayQueue<T>implements MyQueue<T> {
    int MaxSize=10;
    Object[] arr=new Object[10];
    int front=0;
    int rear=0;
    @Override
    public boolean isEmpty() {
        return front==rear?true:false ;
    }

    @Override
    public boolean add(T x) {
        if (isfull()){
            throw new RuntimeException("队列已经满了");
        }
        arr[rear]=x;
        rear=(rear+1)%MaxSize;
        return true;
    }

    @Override
    public T peek() {
        return (T) arr[front];
    }

    @Override
    public T poll() {
        return null;
    }

    public boolean isfull(){
     return (rear+1)%MaxSize==front;
    }

}
